// 引入vuex，导出createStore方法
import { createStore } from "vuex";
import axios from "axios";
// 创建stroe实例
const store = createStore({
  // 定义状态
  state() {
    return {
        name:"vivi",
         goods: [],
         foods:[],
    };
  },
  mutations: {
    chang(state,payload){
        state.goods=payload.goods;
        state.foods=payload.foods;
    }
   
  },
  actions: {
    async getData({commit},payload) {
        await axios.get("http://localhost:3006/goods").then((res)=>{
            commit("chang",{
                goods:res.data.data[0].goods,
                foods:res.data.data[0].goods[0].foods
            })
        })
    }

  },
});

// 导出store实例
export default store;